#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;

Mat src, dst;
int element_size = 3;
int max_size = 21;
string outputWindow;
void CallBack_demo(int, void*);

int main()
{
	src = imread("D:/Images/zhang1.jpg");
	if (!src.data)
	{
		printf("can not load image \0XA");
		return -1;
	}
	string inputWindow = "input";
	outputWindow = "output";
	namedWindow(inputWindow, WINDOW_AUTOSIZE);
	namedWindow(outputWindow, WINDOW_AUTOSIZE);
	cv::createTrackbar("Element size:", outputWindow, &element_size, max_size, CallBack_demo);
	CallBack_demo(0, 0);


	waitKey(0);
	return 0;
}

void CallBack_demo(int, void*)
{
	int s = element_size * 2 + 1;
	Mat structureElement = getStructuringElement(MORPH_RECT, Size(s, s), Point(-1, -1));
	//dilate(src, dst, structureElement, Point(-1, -1), 1);
	erode(src, dst, structureElement, Point(-1, -1), 1);
	imshow(outputWindow, dst);
	return;
}
